package main

import (
	"fmt"
	"gin-project/database"
	auth_router "gin-project/router/auth"
	user_router "gin-project/router/user"
	"net/http"
	"os"

	"github.com/gin-gonic/gin"
	"gopkg.in/ini.v1"
)

func main() {
	r := gin.Default()
	database.Init()
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"message": "pong",
		})
	})
	user_router.UserRouterInit(r)
	auth_router.AuthRouterInit(r)
	cfg, iniErr := ini.Load("config.ini")
	if iniErr != nil {
		fmt.Println("配置文件读取错误", iniErr)
		os.Exit(1)
	} else {
		fmt.Println("配置文件读取成功")
	}
	port := cfg.Section("").Key("port").String()
	r.Run(":" + port)
	fmt.Println("server is listening at port:", port)
}
